package com.site.action.backend.dining;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.site.dto.dining.BanquetHallBizBean;
import com.site.service.dining.BanquetHallService;
import com.site.util.PropertyUtils;
import com.site.util.base.action.BaseAction;
import com.site.util.base.service.BaseService;
import com.site.util.common.fileupload.FileUploadHandle;
import com.site.util.constant.Constants;

/**
 * 宴会厅Action
 * @author win7
 *
 */
public class BanquetHallAction extends BaseAction {
	private static final long serialVersionUID = 6141544316035816442L;
	
	private BanquetHallBizBean banquetHallBizBean;
	
	private List<BanquetHallBizBean> banquetHallBizBeans;
	
	private BanquetHallService banquetHallService;
	
	public List<BanquetHallBizBean> getBanquetHallBizBeans() {
		return banquetHallBizBeans;
	}
	public void setBanquetHallBizBeans(List<BanquetHallBizBean> banquetHallBizBeans) {
		this.banquetHallBizBeans = banquetHallBizBeans;
	}

	public BanquetHallBizBean getBanquetHallBizBean() {
		return banquetHallBizBean;
	}

	public void setBanquetHallBizBean(BanquetHallBizBean banquetHallBizBean) {
		this.banquetHallBizBean = banquetHallBizBean;
	}
	@Resource
	public void setBanquetHallService(BanquetHallService banquetHallService) {
		this.banquetHallService = banquetHallService;
	}
	/**
	 * 根据条件获得所有宴会厅数据
	 * @return
	 */
	public String getBanquetHalls(){
		if(queryPage == null){
			super.initPagination();
		}
		banquetHallBizBeans = banquetHallService.getBanquetHalls(queryPage, banquetHallBizBean);
		return "getBanquetHalls";
	}
	
	/**
	 * 增加页面
	 * @return
	 */
	public String getBanquetHallAdd(){
		return "getBanquetHallAdd";
	}

	/**
	 * 增加
	 * @return
	 */
	public String banquetHallAdd(){
		if(null != banquetHallBizBean && checkData(banquetHallBizBean)){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("banquetHallBizBean", banquetHallBizBean);
			if(null != files && !files.isEmpty()){
				// 上传对象 start 
				FileUploadHandle fileUploadHandle = new FileUploadHandle();
				fileUploadHandle.setRequest(request);
				// 取得上传文件类型
				fileUploadHandle.setAllowedTypes(Constants.UPDATE_FILE_TYPES);
				// 取得上传文件大小
				fileUploadHandle.setMaxSize(Constants.FILE_SIZE);
				fileUploadHandle.setFiles(files);
				fileUploadHandle.setFilesName(getFilesFileName());
				// 上传对象 end
				map.put("fileUploadHandle", fileUploadHandle);
			}
			banquetHallService.execute(map, BaseService.COMMAND_ADD);
			super.setMessageID("SYS_MSG_00022");
		} else{
			return getBanquetHallAdd();
		}
		super.setBackurl(request.getContextPath() + "/banquetHall/banquetHallAction!getBanquetHalls.do?banquetHallBizBean.rid="+banquetHallBizBean.getRid());
		return "toMessage";
	}
	/**
	 * 数据检查
	 * @param banquetHallBizBean2
	 * @return
	 */
	private boolean checkData(BanquetHallBizBean banquetHallBizBean) {
		boolean mark = true;
		if(null != banquetHallBizBean){
			
		}
		return mark;
	}
	/**
	 * 修改页面
	 * @return
	 */
	public String getBanquetHallEdit(){
		if(banquetHallBizBeans != null && !banquetHallBizBeans.isEmpty()){
			for (BanquetHallBizBean banquetHallBizBean : banquetHallBizBeans) {
				if(null != banquetHallBizBean && banquetHallBizBean.getId() != null){
					banquetHallBizBean = banquetHallService.getEntityById(banquetHallBizBean.getId());
					PropertyUtils.copyNotNullProperties(this.banquetHallBizBean, banquetHallBizBean);
				}
			}
		}
		return "getBanquetHallEdit";
	}
	/**
	 * 修改
	 * @return
	 */
	public String banquetHallEdit(){
		if(banquetHallBizBean.getId() != null){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("banquetHallBizBean", banquetHallBizBean);
			if(null != files && !files.isEmpty()){
				// 上传对象 start 
				FileUploadHandle fileUploadHandle = new FileUploadHandle();
				fileUploadHandle.setRequest(request);
				// 取得上传文件类型
				fileUploadHandle.setAllowedTypes(Constants.UPDATE_FILE_TYPES);
				// 取得上传文件大小
				fileUploadHandle.setMaxSize(Constants.FILE_SIZE);
				fileUploadHandle.setFiles(files);
				fileUploadHandle.setFilesName(getFilesFileName());
				// 上传对象 end
				map.put("fileUploadHandle", fileUploadHandle);
			}
			banquetHallService.execute(map, BaseService.COMMAND_UPDATE);
			super.setMessageID("SYS_MSG_00022");
		}
		super.setBackurl(request.getContextPath() + "/banquetHall/banquetHallAction!getBanquetHalls.do?banquetHallBizBean.rid="+banquetHallBizBean.getRid());
		return "toMessage";
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String banquetHallDelete(){
		
		if(banquetHallBizBeans != null && !banquetHallBizBeans.isEmpty()){
			Map<String, Object>  map = new HashMap<String, Object>();
			map.put("request", request);
			for (BanquetHallBizBean banquetHallBizBean : banquetHallBizBeans) {
				if(null != banquetHallBizBean && banquetHallBizBean.getId() != null){
					map.put("banquetHallBizBeans", banquetHallBizBean);
					banquetHallService.execute(map, BaseService.COMMAND_DELETE);
				}
			}
			super.setMessageID("SYS_MSG_00022");
		}
		super.setBackurl(request.getContextPath() + "/banquetHall/banquetHallAction!getBanquetHalls.do?banquetHallBizBean.rid="+banquetHallBizBean.getRid());
		return "toMessage";
	}
}
